package com.autodesk.utility;

import java.util.LinkedList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;



public class FeatureXMLHandler extends DefaultHandler {

	Boolean currentElement = false;
	String currentValue = null;
	List<Feature>   featureList;
	Feature currentFeature = null;

	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		currentElement = true;
		if( localName.equalsIgnoreCase("Items") )
		{
			featureList = new LinkedList<Feature>();
		}
		else if( localName.equalsIgnoreCase(Feature.Class ) )
		{
			currentFeature = new Feature();
		}

	}


	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		currentElement = false;
		if( localName.equalsIgnoreCase(Feature.Class))
		{
			featureList.add(currentFeature);
			currentFeature = null;
		}
		else if( localName.equalsIgnoreCase("Items"))
		{
			
		}
		else
		{
			currentFeature.attributes.put(localName, currentValue);
		}

	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

		if (currentElement) {
			currentValue = new String(ch, start, length);
			currentElement = false;
		}

	}
}
